﻿<%@ Control Language="C#" AutoEventWireup="True" CodeBehind="SoanCauHoi.ascx.cs" Inherits="Main.Administrator.SoanCauHoi" %>
<%@ Register Src="~/Controls/FCKEditor.ascx" TagName="FCKEditor" TagPrefix="uc1" %>
    <!--Đoạn JavaScript Ẩn hiện các element tren Form -->
<script type="text/javascript">
    function ThongBao(val)
    {
        if(val=="Max")
            alert("Số đáp án tối đa là 10.");
        else
            alert("Số đáp án tối thiểu là 2.");
    }
    function KiemTraCauHoiCon(id, id1)
    {
        if(CheckNoiDung(id))
        {
            var drop = document.getElementById(id1);
            if(drop.selectedIndex<=0)
            {
                alert("Bạn chưa chọn độ khó cho câu hỏi con này.");
                return false;
            }
            return  CheckDapAnDung();
        }
        else
        {
            return false;
        }
        
    }
    function Check(id, id1,id2,id3,id4)
    {
        if(CheckNoiDung(id))
        {
            var drop1 = document.getElementById(id1);
            var drop2 = document.getElementById(id2);
            var drop3 = document.getElementById(id3);        
            var drop4 = document.getElementById(id4);
            var kq='';
            if(drop1.selectedIndex<=0)
                kq='\n-Chưa chọn chuyên mục';
            if(drop2.selectedIndex<=0)
                kq+='\n-Chưa chọn kỹ năng';
            if(drop3.selectedIndex<=0)
                kq+='\n-Chưa chọn độ khó';
            if(drop4.selectedIndex<=0)
                kq+='\n-Chưa chọn loại câu hỏi';
            if(kq!=''){
                alert(kq);
                return false;
            }
            if(drop4.selectedIndex > 1)
                return true;
            return  CheckDapAnDung();
        }
        else
        {
            return false;
        }
    }
     function CheckNoiDung(id)
     {
        return true;
//        var ifram = document.getElementsByTagName("input");
//        for(var i=0; i<allInput.length; i++)
//            if(allInput[i].type=="hidden" && allInput[i].id.indexOf(id)!=-1 && allInput[i].id.indexOf("Config") == -1 && allInput[i].value == '')
//            {
//                alert('-Chưa nhập nội dung câu hỏi.');
//                return false;
//            }
//        return true;
     }
    function CheckDapAnDung()
    {
        var allChk = document.getElementsByTagName("input");
        for(var i=0; i<allChk.length; i++)
            if(allChk[i].type == "checkbox" && allChk[i].name.indexOf("chkDaoDapAn")<1 && allChk[i].name.indexOf("chkCauDan")<1 && allChk[i].checked == true )
                return true;
        alert("Bạn chưa chọn đáp án đúng");
        return false;
    }
    
    function CheckCauDan(id)
    {
        if(document.getElementById(id).value == '')
        {
            alert('Vui lòng nhập nội dung câu dẫn.');
            return false;
        }
        return true;
    }
</script>
<asp:ScriptManager ID="ScriptManager1" runat="server"  />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<div id="Location" class="Location" runat="server"><a href="../Administrator.aspx">Administrator Page</a> >> <a href="../Administrator.aspx?option=content">Quản lý câu hỏi</a> >> </div>
<div id="Notice" class="Notice" runat="server" visible="false"></div>
<div id="Errors" class="Errors" runat="server" visible="false"></div>
<div id="Form">
   <%-- <asp:ValidationSummary ID="ValidationSummary1"  ShowMessageBox="true" ShowSummary="false" runat="server" />--%>
    <!--Hạn chế dùng Server Control-->
    <div style="clear:both;"></div>
    <%--Nhập nội dung câu hỏi--%>
    <div style="float:left; width:67%;">
        <fieldset>
            <legend>Nội Dung Câu Hỏi</legend>
            <table style="width:100%; padding:5px;" border="0" cellpadding="0" cellspacing="0" >
                <tr>
                    <td colspan="2" style="width: 613px">
                        <uc1:FCKEditor ID="FCKEditor1" runat="server" Width="100%" Height="500px" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="right" style="width: 613px" >
                        <div class="Button" style="float:right;">
                            <a class="Button2" href="#" visible="false" onclick="return false;" id="btnCauDan" runat="server">Chọn Câu Dẫn</a>
                            <asp:LinkButton ID="btnSave" runat="server"  OnClick="btnSave_Click"><span class="Save">Lưu</span></asp:LinkButton>
                            <asp:LinkButton ID="btnCancel" runat="server" CausesValidation="false"  OnClick="btnCancel_Click"><span class="Cancel">Hủy</span></asp:LinkButton>
                            <asp:LinkButton runat="server"  CssClass="Button2" CausesValidation="false" id="btnThemCauHoiCon" Text="Thêm câu hỏi con" OnClick="btnThemCauHoiCon_Click" Visible="False"></asp:LinkButton>
                        </div>
                    </td>
                </tr>
            </table>
        </fieldset>
        <div class="ui-widget-content ui-corner-all" id="pCauDan" style="display: none;">
            <h3 class="ui-widget-header ui-corner-all">&nbsp;Danh Sách Câu Dẫn Hiện Có</h3>
            <p>
             <asp:GridView DataKeyNames="MaCauHoi" SkinID="GridViewSkin" ID="GridView1" runat="server" 
                AutoGenerateColumns="False" AllowPaging="True" ShowFooter="true"
                OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDeleting="GridView1_RowDeleting" 
                OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" 
                OnRowUpdating="GridView1_RowUpdating" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound"
                >
                <Columns>
                    <asp:TemplateField HeaderText="Chọn">
                        <ItemTemplate>
                            <asp:CheckBox ID="chkCauDan"  runat="server" EnableViewState="true"/>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:Label id="lblChk" runat="server" Text=''></asp:Label>
                        </EditItemTemplate>
                         <FooterTemplate>
                            <asp:LinkButton runat="server" CausesValidation="false" id="btnChon" CommandName="Chon">
                                <asp:Image ID="imgSave" runat="server" SkinID="Save"  />
                            </asp:LinkButton>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="ID">
                        <ItemTemplate>
                            <asp:Label id="lblMaCauHoi" runat="server" Text='<%# Eval ( "MaCauHoi" ) %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:Label id="lblMaCauHoi_e" runat="server" Text='<%# Eval ( "MaCauHoi" ) %>'></asp:Label>
                        </EditItemTemplate>
                         <FooterTemplate>
                            <asp:Label id="lblMaCauHoi_n" runat="server" Text='[Auto]'></asp:Label>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Nội Dung">
                        <ItemTemplate>
                            <asp:Label id="lblNoiDung" runat="server" Text='<%# Eval ( "NoiDung" ) %>'></asp:Label>
                        </ItemTemplate>
                         <EditItemTemplate>
                            <asp:TextBox ID="txtNoiDung_e" runat="server" Text='<%# Eval ( "NoiDung" ) %>'></asp:TextBox>
                        </EditItemTemplate>
                         <FooterTemplate>
                            <asp:TextBox ID="txtNoiDung_n" runat="server" Text=''></asp:TextBox>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Thao T&#225;c">
                        <ItemTemplate>
                            <asp:LinkButton ID="lnkEdit" CausesValidation="false" CommandName="Edit" runat="server" ToolTip="Sửa">
                                <asp:Image ID="imgEdit" runat="server" SkinID="Edit"  />
                            </asp:LinkButton>
                            <asp:LinkButton ID="lnkDelete"  CausesValidation="false" CommandName="Delete" runat="server" ToolTip="Xóa" OnClientClick="return confirm('Bạn có muốn xóa thật không?');">
                               <asp:Image ID="imgDelete" runat="server" SkinID="Delete"  />
                            </asp:LinkButton>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:LinkButton ID="lnkSave" runat="server" CausesValidation="false" CommandName="Update" ToolTip="Save">
                                <asp:Image ID="imgSave" runat="server" SkinID="Save"  />
                            </asp:LinkButton>
                            <asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="false" CommandName="Cancel" ToolTip="Cancel">
                                <asp:Image ID="imgCancel" runat="server" SkinID="Cancel"   />
                            </asp:LinkButton>
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:LinkButton ID="lnkInsert" runat="server" CausesValidation="false" CommandName="Insert" ToolTip="Insert">
                                <asp:Image ID="imgInsert" runat="server" SkinID="Insert" />
                            </asp:LinkButton>
                        </FooterTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            </p>
        </div>
    </div>
    <%--End nhập nội dung cau hỏi--%>
    <%--Phần thông tin câu hỏi và đáp án--%>
    <div style="float:right; width:31%; ">
        <div style="clear:both;"></div>
        <fieldset id="fChuyenMuc" runat="server">
            <legend>Chuyên Mục</legend>
            <asp:ListBox ID="lstCatagories" runat="server" Width="99%"></asp:ListBox>
             <asp:RequiredFieldValidator ID="RequiredFieldValidator14"  runat="server" ErrorMessage="Chưa chọn chuyên mục" ControlToValidate="lstCatagories" InitialValue="Chọn chuyên mục">
             </asp:RequiredFieldValidator>
        </fieldset>
        <fieldset id="fThongTinCauHoi" runat="server">
            <legend>Thông Tin Câu Hỏi</legend>
            <table border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td style="width:45%">Kỹ Năng</td>
                    <td style="width:60%"> 
                        <asp:DropDownList ID="ddlKyNang" runat="server" style="width:100%;"></asp:DropDownList>
                    </td>   
                </tr>
                <tr>
                    <td style="height: 22px">Độ Khó</td>
                    <td style="height: 22px">
                        <asp:DropDownList id="ddlDoKho" runat="server" style="width:100%;"></asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td >Loại Câu Hỏi</td>
                    <td>
                            <asp:DropDownList id="ddlLoaiCauHoi" style="width:100%;" runat="server" OnSelectedIndexChanged="ddlLoaiCauHoi_SelectedIndexChanged" AutoPostBack="True" >
                            </asp:DropDownList>
                     </td>
                </tr>
            </table>
        </fieldset>
        <%--Phần này chỉ hiện thị khi người dùng chọn thêm câu hỏi con --%>
        <fieldset id="fIdCauHoiCha" runat="server" visible="false">
            <legend>Thông Tin Câu Hỏi</legend>
            ID Câu hỏi cha : <asp:Label ID="lblIDCahoiCha" runat="server"></asp:Label>
        </fieldset>
        <fieldset id="fMucDoCauHoiCon" runat="server" visible="false">
            <legend>Độ khó</legend>
            <asp:DropDownList id="ddlDoKhoCauHoiCon" runat="server" style="width:80%;"></asp:DropDownList>
        </fieldset>
        <%--Phần Đáp Án--%>
        <div id="pDapAn">
        <fieldset id="fDapAn" runat ="server">
            <legend>Thông Tin Đáp Án</legend>
            <table id="tblDapAn"  width ="100%" border="0" cellpadding="0" cellspacing="0" >
                <tr id="trDaA" runat="server">
                    <td>A:</td>
                    <td style="width:80%">
                        <asp:TextBox id="txtDapAnA" TextMode="MultiLine" style="width:100%;"  runat="server" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"  ErrorMessage="Chưa nhập đáp án A." ControlToValidate="txtDapAnA"></asp:RequiredFieldValidator>
                    </td>
                    <td align="right">
                        <asp:CheckBox ID="chkA" runat="server" ToolTip="Đáp Án Đúng?" />
                    </td>
                </tr>
                <tr id="trDaB" runat="server">
                    
                    <td>B:</td>
                    <td >
                        <asp:TextBox id="txtDapAnB" TextMode="MultiLine" style="width:100%;"  runat="server"  ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"  ErrorMessage="Chưa nhập đáp án B." ControlToValidate="txtDapAnB"></asp:RequiredFieldValidator>            
                    </td>
                    <td align="right">
                        <asp:CheckBox ID="chkB" runat="server" ToolTip="Đáp Án Đúng?" />
                    </td>
                </tr>
                <tr id="trDaC" runat="server">
                    <td >C:</td>
                    <td>
                        <asp:TextBox id="txtDapAnC" TextMode="MultiLine" style="width:100%;" runat="server" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"  ErrorMessage="Chưa nhập đáp án C." ControlToValidate="txtDapAnC"></asp:RequiredFieldValidator>
                    </td>
                    <td align="right">
                        <asp:CheckBox ID="chkC" runat="server" ToolTip="Đáp Án Đúng?" />
                    </td>
                </tr>
                <tr id="trDaD" runat="server">
                    
                    <td>D:</td>
                    <td>
                        <asp:TextBox id="txtDapAnD" TextMode="MultiLine" style="width:100%;" runat="server" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"  ErrorMessage="Chưa nhập đáp án D." ControlToValidate="txtDapAnD"></asp:RequiredFieldValidator>         
                    </td>
                    <td align="right">
                        <asp:CheckBox ID="chkD" runat="server" ToolTip="Đáp Án Đúng?" />
                    </td>
                </tr> 
                <tr id="trDaE" runat="server">
                    
                    <td>E:</td>
                    <td>
                        <asp:TextBox id="txtDapAnE" TextMode="MultiLine" style="width:100%;" runat="server" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"  ErrorMessage="Chưa nhập đáp án E." ControlToValidate="txtDapAnE"></asp:RequiredFieldValidator>
                    </td>
                    <td align="right">
                        <asp:CheckBox ID="chkE" runat="server" ToolTip="Đáp Án Đúng?" />
                    </td>
                </tr> 
                 <tr id="trDaF" runat="server">
                    
                    <td>F:</td>
                    <td>
                        <asp:TextBox id="txtDapAnF" TextMode="MultiLine" style="width:100%;" runat="server" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"  ErrorMessage="Chưa nhập đáp án F." ControlToValidate="txtDapAnF"></asp:RequiredFieldValidator>
                    </td>
                    <td align="right">
                        <asp:CheckBox ID="chkF" runat="server" ToolTip="Đáp Án Đúng?" />
                    </td>
                </tr> 
                <tr id="trDaG" runat="server">
                    
                    <td>G:</td>
                    <td>
                        <asp:TextBox id="txtDapAnG" TextMode="MultiLine" style="width:100%;" runat="server" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"  ErrorMessage="Chưa nhập đáp án G." ControlToValidate="txtDapAnG"></asp:RequiredFieldValidator>
                        </td>
                    <td align="right">
                        <asp:CheckBox ID="chkG" runat="server" ToolTip="Đáp Án Đúng?" />
                    </td>
                </tr> 
                <tr id="trDaH" runat="server">
                    <td>H:</td>
                    <td>
                        <asp:TextBox id="txtDapAnH" TextMode="MultiLine" style="width:100%;" runat="server" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server"  ErrorMessage="Chưa nhập đáp án H." ControlToValidate="txtDapAnH"></asp:RequiredFieldValidator>
                    </td>
                    <td align="right">
                        <asp:CheckBox ID="chkH" runat="server" ToolTip="Đáp Án Đúng?" />
                    </td>
                </tr> 
                <tr id="trDaI" runat="server">
                    <td>I:</td>
                    <td>
                        <asp:TextBox id="txtDapAnI" TextMode="MultiLine" style="width:100%;" runat="server" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server"  ErrorMessage="Chưa nhập đáp án I." ControlToValidate="txtDapAnI"></asp:RequiredFieldValidator>
                    </td>
                    <td align="right">
                        <asp:CheckBox ID="chkI" runat="server" ToolTip="Đáp Án Đúng?" />
                    </td>
                </tr>
                <tr id="trDaJ" runat="server">
                    <td>J:</td>
                    <td>
                        <asp:TextBox id="txtDapAnJ" TextMode="MultiLine" style="width:100%;" runat="server" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator10"  runat="server" ErrorMessage="Chưa nhập đáp án J." ControlToValidate="txtDapAnJ"></asp:RequiredFieldValidator>
                    </td>
                    <td align="right">
                        <asp:CheckBox ID="chkJ" runat="server" ToolTip="Đáp Án Đúng?" />
                    </td>
                </tr>
                
            </table>
        <%--End Đáp Án--%>
            <table width="100%">
                <tr>
                    <td >
                        <div class="Button" style="float:right;">
                            <asp:LinkButton runat="server"  CssClass="Button2" CausesValidation="false" id="lnkThemDapAn"  Text="Thêm đáp án" OnClick="lnkThemDapAn_Click" ></asp:LinkButton>
                           <asp:LinkButton runat="server"  CssClass="Button2" CausesValidation="false" id="lnkRemove"  Text="Remove" OnClick="lnkRemove_Click" ></asp:LinkButton>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID="chkDaoDapAn"  runat="server" Text="Được phép đảo đáp án" />
                    </td>
                </tr>
            </table>
            <asp:HiddenField ID="HidMaCauHoi" Value="" runat="server" />
            <asp:HiddenField ID="HidMaCauHoiCha" Value="" runat="server" />
            <asp:HiddenField ID="HidCommand" Value="" runat="server" />
            <asp:HiddenField ID="hidC" Value="" runat="server" />
            <asp:HiddenField ID="hidD" Value="" runat="server" />
            <asp:HiddenField ID="hidE" Value="" runat="server" />
            <asp:HiddenField ID="hidF" Value="" runat="server" />
            <asp:HiddenField ID="hidG" Value="" runat="server" />
            <asp:HiddenField ID="hidH" Value="" runat="server" />
            <asp:HiddenField ID="hidI" Value="" runat="server" />
            <asp:HiddenField ID="hidJ" Value="" runat="server" />
            <asp:HiddenField ID="hidA" Value="" runat="server" />
            <asp:HiddenField ID="hidB" Value="" runat="server" />
            <input type="hidden" runat="server" id="hidSoDapAn" value="4" />
        </fieldset>
        </div>
    </div>
    <div style="clear:both;"></div>
</div>
<script type="text/javascript">
    function ChkClick(tableId,me)
    {
          var table = document.getElementById(tableId);
          var chkboxes = table.getElementsByTagName('input');
          for (var i = 0; i < chkboxes.length; i++)
          {
                if (chkboxes[i].type == 'checkbox' && chkboxes[i].checked == true && chkboxes[i].id != me)
                {
                    chkboxes[i].checked = false;
                }
          }
    }
</script>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
       <ProgressTemplate>
                <div class="overlay" id="divProgress" style="position: absolute">
                    <center>
                        <asp:Image runat="server" ID="AjaxLoading" SkinID="AjaxLoadingIndicator" />
                    </center>
                </div>
        </ProgressTemplate>
</asp:UpdateProgress>